
using System;
using FireStarterModeller.BO;
using FireStarterModeller.Logic;
using FireStarterModeller.Test.BO;
using FireStarterModeller.UI.CodeGeneration;
using Habanero.BO;

namespace FireStarterModeller.Test.UI
{
    public class UITestPackBuilder
    {
        public static DMSolution CreateDMSolution()
        {
            return CreateDMSolution(2);
        }
        public static DMSolution CreateDMSolution(int noOfClasses)
        {
            DMSolution dmSolution = new DMSolution("TestSolution"); //TestUtilsDMSolution.CreateSavedDMSolution();
            SolutionCreator solutionCreator = new SolutionCreator();
            solutionCreator.CreateDefaultAssembly(dmSolution);
            solutionCreator.UpdateNewSolution(dmSolution);

            for (int i = 1; i <= noOfClasses; i++)
            {
                CreateDMClassWithObjectIdentity(dmSolution, "Class" + i);
            }

            return dmSolution;
        }

        public static GenerationSettings CreateGenerationSettings(DMSolution dmSolution)
        {
            GenerationSettings generationSettings = new GenerationSettings();
            dmSolution.GenerationSettings = generationSettings;
            //new CodeGenerationController(generationSettings).GenerateDefaultSolutionTypes();
            generationSettings.SolutionName = dmSolution.SolutionName;
            generationSettings.SolutionDirectory = @"D:\temp\temp";
            generationSettings.HabaneroDllPath = @"D:\systems\habanero\trunk\bin";
            return generationSettings;
        }

        public static DMClass CreateDMClassWithObjectIdentity(DMSolution dmSolution, string className)
        {
            return TestUtilsDMClass.CreateDMClassWithObjectIdentity(dmSolution, className);
        }

        public static DMProperty CreateDMProperty(DMClass dmClass, string propertyName, string typeAssembly, string typeName)
        {
            return TestUtilsDMProperty.CreateDMProperty(dmClass, propertyName, typeAssembly, typeName);
        }

        public static DMRelationship CreateDMRelationshipAsOneToMany(DMClass parentClass, DMClass childClass)
        {
            return TestUtilsDMRelationship.CreateDMRelationshipAsOneToMany(parentClass, childClass);
        }

        //public static DMRelationship CreateDMRelationshipAsOneToOne(DMClass classWithPK, DMClass classToReceiveFK)
        //{
        //    throw new NotImplementedException();
        //}

        private static void CreateDefaultProjectTypeGenerations(DMSolution dmSolution)
        {
            BusinessObjectCollection<ProjectType> projectTypes = BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection<ProjectType>("", "Name");
            foreach (ProjectType projectType in projectTypes)
            {
                ProjectTypeGeneration projectTypeGeneration = new ProjectTypeGeneration();
                projectTypeGeneration.ProjectName = dmSolution.SolutionName + "." + projectType.Name;
                projectTypeGeneration.GenerationSettings = dmSolution.GenerationSettings;
                projectTypeGeneration.ProjectType = projectType;
                projectTypeGeneration.ToBeGenerated = true;
            }
        }
    }
}